package com.djc8.controller.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.djc8.entity.BookBean;
import com.djc8.entity.BookReviewsBean;
import com.djc8.entity.BookReviewsSimpleBean;
import com.djc8.entity.Page;
import com.djc8.model.Model;

/**
 * Servlet implementation class GetBookReviewList
 */
public class GetBookReviewList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String page=request.getParameter("page");
		
		String row=request.getParameter("rows");
		
		Model model=new Model();
		Page p=null;
		if(page!=null && row!=null && !page.equals("") && !row.equals("") )
		{
			p=model.doPageForBookReview(Integer.parseInt(page), Integer.parseInt(row));
		}
		else
		{
			p=model.doPageForBookReview(1, 10);
		}
		
		List<BookReviewsBean> list=new ArrayList<BookReviewsBean>(p.getPageList());
		
		JSONArray jsonArray=new JSONArray();
		for (BookReviewsBean bean : list) {
			
			JSONObject obj=new JSONObject();
			
			BookReviewsSimpleBean bs=bean.getBookReviewsSimpleBean();
			
			
			obj.put("BookReviewsSimple",bs.getBookReviewsSimple() );
			obj.put("Book_ID",bs.getBookId());
			obj.put("us_id", bs.getUsId());
			obj.put("BookReviewSimple_Title", bs.getBookReviewSimpleTitle());
			obj.put("BookReviewSimple_Date", bs.getBookReviewSimpleDate().toString());
			obj.put("ISDelete", bs.isISDelete());
			
			obj.put("BookReviewsDetial_Content", bean.getBookReviewsDetialBean().getBookReviewsDetialContent());
			
			jsonArray.add(obj);
		}
		JSONObject obj=new JSONObject();
		obj.put("total", p.getTotalNum());
		obj.put("rows", jsonArray);
		
		//jsonArray.add(new UserInfoBean(0,0,"1","1","2","3","4",null,null));
		
		response.getWriter().print(obj.toString());
		//System.out.println(jsonArray.toString());
	}

}
